<?php
/*
	query.class
		处理各种querystring，和伪静态的处理
	#author: corrie
	#update: corrie
	#latest: 03/02/09
	#version: 1.0
*/

if(!defined('CORE')) {exit('Access Denied');}

class Query{
	
	function Query(){
	}
	
	function insert($data=array()){
	}
	
	/*-----------------------------
		function:	getfiled
		introduce:	返回原格式的可更新表单数据，主要用于UPDATE
		author:		corrie
	------------------------------*/
	function getupdatefield($field='', $prefield=''){
		if($field=='' || empty($field)){
			if(isset($_POST['field']))
				$field = $_POST['field'];
			else
				return false;
		}
		if($prefield=='' || empty($prefield)){
			if(isset($_POST['prefield']))
				$prefield = $_POST['prefield'];
			else
				return $field;
		}
		if($prefield==$field)return false;
		$array = array();
		foreach($field as $key=>$sign){
			foreach($sign as $k=>$v){
				if($v!=$prefield[$key][$k]){
					$array[$key][$k] = $v;
				}
			}
		}
		if(!empty($array))return $array;
	}
	
	/*------------------------------
		function:	getfiled
		introduce:	返回处理后的可更新表单数据（直接提交到数据库使用）
		author:		corrie
	------------------------------*/
	function getupdatedata($field='', $prefield=''){
		if($field=='' || empty($field)){
			if(isset($_POST['field']))
				$field = $_POST['field'];
		}
		if($prefield=='' || empty($prefield)){
			if(isset($_POST['prefield']))
				$prefield = $_POST['prefield'];
		}
		if($prefield==$field)return array();
		$data = array();
		$datas = array();
		foreach($field as $key=>$sign){
			foreach($sign as $k=>$v){
				if(isset($prefield[$key][$k])){					
					if($v!=$prefield[$key][$k]){
						$data[$key][$k] = is_array($v) ? arr2str($v) : $v;
					}
				}else{
					$data[$key][$k] = is_array($v) ? arr2str($v) : $v;
				}
			}
		}
		return $data;
	}
	/*
	*	absfield	整理和验证提取的数据
	*
	*/
	function absfield($arr, $field=array(), $signer=''){
		if(!$field)$field = $_POST['field'];
		if(!$signer)$signer = 1;
		$data = array();
		foreach($arr as $v){
			$data[$v] = is_array($field[$signer][$v]) ? arr2str($field[$signer][$v]) : $field[$signer][$v];
		}
		return $data;
	}
	/*
	*	abs2field	整理和验证提取的数据。二个层级，适合提取后的数据.
	*
	*/
	function abs2field($arr, $field=array()){
		//if(!$field)$field = $_POST['field'];
		$data = array();
		foreach($arr as $v){
			$data[$v] = is_array($field[$v]) ? arr2str($field[$v]) : $field[$v];
		}
		return $data;
	}
	/*
	*	dofield	整理和验证提取的数据
	*
	*/
	function dofield(){
	}
	
	function vefield(){
	}
	
	function vvv(){
		return "abc";
	}
	
}
?>